﻿using DotNetty.Codecs.Http;
using DotNetty.Codecs.Http.Multipart;
using DotNetty.Common.Utilities;
using System.Collections.Generic;
using System.Text;

namespace DotNetty.Framework.BaseModel
{
    public abstract class AbstractHttpContext
    {
        public string Host { get; set; }
        public string Path { get; set; }
        public string QueryString { get; set; }
        public string Channel { get; set; }
        public HttpHeaders Headers { get; set; }
        public HttpMethod Method { get; set; }
        public List<IFileUpload> Files { get; set; }
        public Dictionary<string, string> FormBody { get; set; }
        public byte[] Body { get; set; }
        public string GetParameterAsString() => Encoding.UTF8.GetString(this.Body);
        public object ResponseBody { get; set; }
        public Encoding ResponseEncoding { get; set; }
        public Dictionary<AsciiString, string> ResponseHeader { get; set; } = new Dictionary<AsciiString, string>();
        public HttpResponseStatus ResponseStatus { get; set; }
        public string GetHeader(AsciiString ascii)
        {
            if (this.Headers.TryGetAsString(ascii, out string value))
                return value;

            return string.Empty;
        }
        public string GetHeader(string name)
        {
            AsciiString ascii = new AsciiString(name);
            return this.GetHeader(ascii);
        }
    }
}
